package com.avcdata.national.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.avcdata.aoscustommade.R;
import com.avcdata.national.fragment.ScaleFragment;
import com.avcdata.national.module.AllLableBean;

import java.util.List;

/**
 * Created by lucasey on 2017/1/9.
 */

public class allLableAdapter extends BaseAdapter {

    private List<AllLableBean> list;
    private List<Integer> color;
    private Context context;

    public allLableAdapter(List<AllLableBean> list, List<Integer> color, Context context) {
        this.list = list;
        this.color = color;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size ();
    }

    @Override
    public Object getItem(int position) {
        return list.get ( position );
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        viewHolder holder;
        if (convertView == null) {
            holder = new viewHolder ();
            convertView = View.inflate ( context, R.layout.item_all_lable, null );
            holder.iv = (ImageView) convertView.findViewById ( R.id.item_lable_line );
            holder.ll = (LinearLayout) convertView.findViewById ( R.id.item_lable_bg );
            holder.tv = (TextView) convertView.findViewById ( R.id.item_lable_name );
            convertView.setTag ( holder );
        } else {
            holder = (viewHolder) convertView.getTag ();
        }

        if (list.get ( position ).selected) {
            holder.ll.setBackgroundResource ( R.drawable.bg_whitecontent_bulestroke );
            holder.tv.setTextColor ( context.getResources ().getColor ( R.color.blue1 ) );
        } else {
            holder.ll.setBackgroundResource ( R.drawable.bg_whitecontent_graystroke );
            holder.tv.setTextColor ( context.getResources ().getColor ( R.color.gray ) );
        }
        holder.iv.setBackgroundColor ( color.get(position) );
        holder.tv.setText ( list.get ( position ).lable );
        return convertView;
    }

    class viewHolder {
        TextView tv;
        ImageView iv;
        LinearLayout ll;
    }

}
